package org.test.joda;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;

/**
 * Created by Hy on 2018/7/19.
 * Joda Time测试1
 */
public class JodaTest1 {
    public static void main(String[] args) {
        DateTime today = new DateTime();
        DateTime torrow = today.plusDays(1);
        System.out.println(today.toString("yyyy-MM-dd"));//2018-07-19
        System.out.println(today.toString("yyyy-MM-dd HH:mm:ss"));//2018-07-19 11:15:47
        System.out.println(torrow.toString("yyyy-MM-dd"));//2018-07-20
        System.out.println(".....................................");

        //获得一个时间的副本，将day设置成自己制定的时间，不改变月份，只改变日期
        DateTime d1 = today.withDayOfMonth(1);
        System.out.println(d1.toString("yyyy-MM-dd HH:mm:ss"));//2018-07-01 11:22:34 当月第一天日期 时间为当前时间
        System.out.println(".....................................");

        LocalDate localDate = new LocalDate();
        System.out.println(localDate);//2018-07-19 当时天
        System.out.println(".....................................");

        //获取当前时间三个月后的月份的最后一天
        localDate = localDate.plusMonths(3).dayOfMonth().withMaximumValue();
        System.out.println(localDate);//2018-10-31
        System.out.println(".....................................");

        //计算二年前第三个月最后一天的日期
        DateTime dateTime = new DateTime();
        DateTime dateTime1 = dateTime.minusYears(2).monthOfYear().setCopy(3).dayOfMonth().withMaximumValue();
        System.out.println(dateTime1.toString("yyyy-MM-dd HH:mm:ss"));//2016-03-31 11:32:48

    }
}
